package com.cet.billingjob.listener;

import com.cet.billingjob.domain.BillingData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;

/**
 * @author 30952
 */
@Slf4j
public class ReportDataRetryListener implements RetryListener {

    @Override
    public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
        BillingData billingData = (BillingData) context.getAttribute("context.state");
        log.info("BillingJob, 信息： {}", billingData);
        log.info("发生异常：{}，进行第{}次重试", context.getLastThrowable().getMessage(), context.getRetryCount());
    }

    @Override
    public <T, E extends Throwable> void onSuccess(RetryContext context, RetryCallback<T, E> callback, T result) {
        RetryListener.super.onSuccess(context, callback, result);
    }
}
